package com.yanqu.road.server.cmd.activity.selectlottery;

import com.yanqu.road.entity.activity.selectlottery.data.SelectLotteryUserData;
import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SelectLotteryProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.selectlottery.SelectLotteryModule;
import com.yanqu.road.server.manger.activity.monjinlottery.pb.SelectLotteryPb;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@CmdApi(reqMsg = SelectLotteryProto.SelectLotterySelectRewardReqMsg.class, respMsg = SelectLotteryProto.SelectLotterySelectRewardRespMsg.class)
@Cmd(code = Protocol.S_SELECT_LOTTERY_SELECT_REWARD, desc = "通用自选抽奖-自选奖励")
public class SelectLotterySelectRewardCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SelectLotteryProto.SelectLotterySelectRewardReqMsg reqMsg = SelectLotteryProto.SelectLotterySelectRewardReqMsg.parseFrom(packet.getBytes());
        SelectLotteryProto.SelectLotterySelectRewardRespMsg.Builder respMsg = SelectLotteryProto.SelectLotterySelectRewardRespMsg.newBuilder();
        try {
            //自选奖励
            player.getModule(SelectLotteryModule.class).selectReward(reqMsg.getActivityId(), reqMsg.getRewardId());
            SelectLotteryUserData userData =  player.getModule(SelectLotteryModule.class).getUserData(reqMsg.getActivityId());
            respMsg.setRet(0);
            respMsg.setUserData(SelectLotteryPb.buildSelectLotteryUserData(userData));
        } catch (BusinessException e) {
            respMsg.setRet(e.getCode());
        }
        player.sendPacket(Protocol.U_SELECT_LOTTERY_SELECT_REWARD, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {}
}
